<?php
class Mobile_AppController extends Zend_Controller_Action
{
    protected $_arrParam = null;
    public function init()
    {
        $layoutPath = TEMPLATE_PATH ."/mobile"  ;
               $option = array (	'layout' 		=> 'app', 
	              	        'layoutPath' 	=> $layoutPath );
        Zend_Layout::startMvc ( $option );
        
        $this->view->controller = $this->_request->getParam('controller');
        $this->view->action = $this->_request->getParam('action');
        $channel=$this->_request->getParam('channel'); // thiet lap kenh video cho app
		$this->view->channel = $channel;
		if(!$channel){$channel=3;}
		$type_news=$this->_request->getParam('type_news');
		$this->view->type_news=$type_news;
		if(!$type_news){$$type_news=1;}
        Zend_Loader::loadClass('FilmInfoModel');
        Zend_Loader::loadClass('AuthModel');
        Zend_Loader::loadClass('ParentTypeModel');
        Zend_Loader::loadClass('RemoveCircumflex');
        Zend_Loader::loadClass('AdvertiseModel');
        
        $this->view->model = new RemoveCircumflex();
        
        $this->view->url = "http://".$_SERVER["HTTP_HOST"]."".$_SERVER["REQUEST_URI"];
        
        $typeModel = new ParentTypeModel();
        $type = $typeModel->getListType();
        $this->view->categories = $type;
        
        $this->_arrParam = $this->_request->getParams();
        $this->view->link = $this->_arrParam;
        
        $device=Zend_Registry::get('device');
        //Zend_Debug::dump($_SERVER);die;
        $server_host = explode('.',$_SERVER['HTTP_HOST'],2);
        $server_host = @$server_host[1];
		//if( $device == 0 ) header("Location: http://".$server_host.$_SERVER['REQUEST_URI']);
    }

    public function indexAction()
    {
        $AdsModel = new AdvertiseModel();
        $FilmInfoModel = new FilmInfoModel();
        if(isset($this->_arrParam['cate']) && !isset($this->_arrParam['type'])){
             //TRANG The loai
            $this->view->ads_top = $AdsModel->getListAdsByPos('category1','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('category1','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('category1','bottom');
    
            $cate = $this->_arrParam['cate'];
            $listFilm = $FilmInfoModel->getListFilmByCate_m($cate); 
            $this->view->listFilm = $listFilm;
            
            $meta_title = $listFilm[0]['name'];
            $this->view->headTitle($meta_title."| Xem24.com");
            $this->view->headKey = $meta_title ;
            
            $ParentTypeModel = new ParentTypeModel();
            $description = $ParentTypeModel->getTypeById($cate);
            $description = $description[0]['description'];
        }
        else if(isset($this->_arrParam['cate']) && isset($this->_arrParam['type'])){
            
             //TRANG The loai
            $this->view->ads_top = $AdsModel->getListAdsByPos('category2','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('category2','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('category2','bottom');
            //
            $cate = $this->_arrParam['cate'];
            $type = $this->_arrParam['type'];
            $cates = $FilmInfoModel->getListFilmByCate_m($cate);
            $j = 0;
            foreach($cates as $item){
                $types = explode('|',$item['type']);
                for($i = 1; $i<count($types);$i++){
                    if($types[$i] == $type){
                        $listFilm[] = $cates[$j];
                    }
                }
                $j++;  
            }
            $name_type = explode('|',$cates[0]['name_types']);
            for($j = 0 ; $j < count($name_type); $j++)
            {
                $name_type[$j] = explode('-',$name_type[$j]);
                if($name_type[$j][0] == $type){
                    $meta_title = $name_type[$j][1];
                }
                
            }
            //$meta_title = $name_type['name'];
            $this->view->headTitle($meta_title." | Xem24.com");
			$this->view->headKey = $meta_title ;
            $this->view->label_top = $meta_title;
           //$this->view->headDescription =$film[0]['description'];
           
            $adapter = new Zend_Paginator_Adapter_Array($listFilm);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(21);       
            $paginator->setPageRange(3);
            $currentPage = $this->_request->getParam('page',1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->paginator=$paginator;
        }else
        if(isset($this->_arrParam['id'])){
            
             //TRANG Chi tieets
            $this->view->ads_top = $AdsModel->getListAdsByPos('detail','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('detail','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('detail','bottom');
            //
            
            $id = $this->_arrParam['id'];
            
            $film = $FilmInfoModel->getFilmById($this->_arrParam['id']);
            // meta cho trang chi tiet
            $meta_title = $film[0]['title_vi'];
            $this->view->headTitle($meta_title." | Xem24.com ");
            $this->view->headKey = $meta_title ;
            $this->view->headDescription =$film[0]['description'];
            
            
            $type = $film[0]['type'];
            $type = explode('|',$type,2);
            $type = intval($type[0]);
            
             $this->view->film = $film;
             $hits = $FilmInfoModel->getHitsById($id);
             $hit = $hits[0]['hits'];
             $FilmInfoModel->updateHitsById($hit+1,$id);
             
             //xuat top xem nhieu
             $topVideo = $FilmInfoModel->getListTop($type);
             $this->view->topvideo = $topVideo;
             
             //xuat video liên quan
             $relatedVideo = $FilmInfoModel->getListRelated($type, $id);
             $this->view->relatedvideo = $relatedVideo;
			 
             
        }else{
            //TRANG CHU
            Zend_Loader::loadClass('TopWeekModel');
			
            $FilmInfoModel = new FilmInfoModel();
            $TopWeekModel =  new TopWeekModel();
			
            $date_default = '2013-1-28';
            $date_default = strtotime($date_default);
            $Date = new Zend_Date();
            $date_now = $Date->get('yyyy-MM-dd');
            $date_now =  strtotime($date_now);
    
            $date_diff = $date_now - $date_default;
            $day_diff = $date_diff / 86400;
            $week_number = ($day_diff - $day_diff%7)/7;
			 $channel=$this->_request->getParam('channel');
			 if(!$channel){
			 $channel="3|1";
			 }
			 
    if($channel==4){
	
	$channel ="4|1";
	}
			//channel kenh cho app
            if($channel){
            $topVideo = $TopWeekModel->getListTopAll_channel($week_number,$channel);
			$nominationVideo = $FilmInfoModel->getListNomination_channel($channel);
			$newVideo = $FilmInfoModel->getListNew_channel($channel);
			} 
            $this->view->topvideo = $topVideo;
            
            $this->view->nominationvideo = $nominationVideo;    
            
            
            $this->view->newvideo = $newVideo;
            
        }
    }
    public function tvonlineAction(){
        $AdsModel = new AdvertiseModel();
         //TRANG Chi tieets
         $this->view->ads_top = $AdsModel->getListAdsByPos('detail','top');
         $this->view->ads_right = $AdsModel->getListAdsByPos('detail','right');
         $this->view->ads_bottom = $AdsModel->getListAdsByPos('detail','bottom');
         
         Zend_Loader::loadClass("TVOnlineModel");
         $TVModel = new TVOnlineModel();
        
         if(isset($this->_arrParam['id'])){
            $id_tv = $this->_arrParam['id'];
            $tv = $TVModel->fetchRow("id = ".$id_tv);
            $this->view->tv = $tv;
            
            //lay them cac kenh khac
            $tvs_dif_vn = $TVModel->TvsDifVN($id_tv);
            $this->view->tvs_dif_vn = $tvs_dif_vn;
            
            $tvs_dif_qt = $TVModel->TvsDifQT($id_tv);
            $this->view->tvs_dif_qt = $tvs_dif_qt;
         }else{
            $tv = $TVModel->fetchRow("play_default = 1 AND status = 1 AND code_mobile != ''");
            if($tv != null){
                $this->view->tv = $tv;
                $id_tv = $tv['id'];
            }else{
                $tv = $TVModel->fetchRow("status = 1 AND code_mobile != ''",'id DESC');
                $this->view->tv = $tv;
                $id_tv = $tv['id'];
            }
            //lay them cac kenh khac
            $tvs_dif_vn = $TVModel->TvsDifVN($id_tv);
            $this->view->tvs_dif_vn = $tvs_dif_vn;
            
            $tvs_dif_qt = $TVModel->TvsDifQT($id_tv);
            $this->view->tvs_dif_qt = $tvs_dif_qt;
         }
    }
    public function searchAction(){
            //TRANG CHU
            $AdsModel = new AdvertiseModel();
            $this->view->ads_top = $AdsModel->getListAdsByPos('home','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('home','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('home','bottom');
            //
              if ($_GET['search']) {
                  $search = $_GET['search'];
                  $filter = new RemoveCircumflex();
                  $search = $filter->filter($search);
                  $this->view->search = $search;
                  $this->_arrParam = array(
                        "title"   =>$search,);
                        
                  $model = new FilmInfoModel();
                  $results  = $model->searchItem($this->_arrParam);
                  
                  $adapter = new Zend_Paginator_Adapter_Array($results);
                  $paginator = new Zend_Paginator($adapter);
                  $paginator->setItemCountPerPage(10);       
                  $paginator->setPageRange(3);
                  $currentPage = $this->_request->getParam('page',1);
                  $paginator->setCurrentPageNumber($currentPage);
                  $this->view->paginator=$paginator;
                  $count = count($results);
                  $this->view->count = $count;
              }     
    }
    public function newsAction(){
        //Tin tuc chi tiet
        $AdsModel = new AdvertiseModel();
        $this->view->ads_top = $AdsModel->getListAdsByPos('home','top');
        $this->view->ads_right = $AdsModel->getListAdsByPos('home','right');
        $this->view->ads_bottom = $AdsModel->getListAdsByPos('home','bottom');
        $type_news=$this->_request->getParam('type_news');
        if(!$type_news){$type_news=1;}
        $this->view->type_news=$type_news;
		
        Zend_Loader::loadClass("NewsModel");
        $ModelN = new NewsModel();
        
        if(isset($this->_arrParam['id'])){
            $object = $ModelN->fetchRow("id='".$this->_arrParam['id']."'");
            
            $hits = $object['hits']+1;
            $ModelN->update(array("hits" => $hits), "id='".$this->_arrParam['id']."'");
            
            $this->view->headTitle($object['title_seo']);
			$this->view->headKey = $object['keyword'];
            $this->view->headDescription = $object['description'];
            $this->view->object = $object;    
            
            $list_related = $ModelN->getRelated($this->_arrParam['id'],$type_news);
            $this->view->list_related = $list_related;
            
        }else{//Toan bo tin tuc
            $this->view->headTitle("Tin tức");
            $this->view->headKey = "tin tuc, tin phim, tin hot, news";
            $this->view->headDescription = "Trang tin tức xem24.com, cập nhật liên tục, tin mới nhất hot nhất";
			
            $list = $ModelN->getListNews($type_news, 1);
            $this->view->list_news = $list;
            $this->view->page = 2;
            $list_nomination = $ModelN->fetchAll("nomination = '1' AND type ='".$type_news."'","id DESC");
            $this->view->list_nomination = $list_nomination;
           
            /**
 * $adapter = new Zend_Paginator_Adapter_Array($list);
 *             $paginator = new Zend_Paginator($adapter);
 *             $paginator->setItemCountPerPage(10);       
 *             $paginator->setPageRange(3);
 *             $currentPage = $this->_request->getParam('page',1);
 *             $paginator->setCurrentPageNumber($currentPage);
 *             $this->view->paginator=$paginator;
 */
        }   
    }
    
     public function loadMorenewsAction(){
        $this->_helper->_layout->disableLayout();
        Zend_Loader::loadClass("NewsModel");
        $ModelN = new NewsModel();
        $page = $this->_arrParam['page'];
        $type_news = $this->_arrParam['type_news'];
        $list = $ModelN->getListNews($type_news, $page);
        if(count($list)){
            $this->view->list_news = $list;
            $this->view->type_news = $type_news;
        }else{
            exit();
        }
    }
    
    public function storyAction(){
        //Tin tuc chi tiet
        try{
        $AdsModel = new AdvertiseModel();
        Zend_Loader::loadClass("StoryModel");
        Zend_Loader::loadClass("CategoryStoryModel");
        $this->view->ads_top = $AdsModel->getListAdsByPos('home','top');
        $this->view->ads_right = $AdsModel->getListAdsByPos('home','right');
        $this->view->ads_bottom = $AdsModel->getListAdsByPos('home','bottom');
        $params = $this->_arrParam;
        $channel=$this->_request->getParam('channel');
        $story_model = new StoryModel();
        $category_model = new CategoryStoryModel();
        $list_category = $category_model->getList();
        $this->view->list_category = $list_category;
        $this->view->channel = $channel;
        if(isset($params['_id'])){
            $story_model->update(array("hits" => new Zend_Db_Expr("hits + 1")), "_id='".$params['_id']."'");
            $object = $story_model->getItem($params['_id']);
            
            $this->view->headTitle($object['Title']);
            $this->view->headDescription = $object['Title'];
            $this->view->object = $object;  
            
            $list_related = $story_model->getRelated($params['_id'], $object['Catelogy']);
            $this->view->list_related = $list_related;
            
        }else{//Toan bo tin tuc
            $this->view->headTitle("Truyện cười");
            $headKey = "truyen, truyen cuoi, truyen cuoi dan gian, truyen cuoi nguoi lon, truyen cuoi hoc tro";
            $headKey .= "truyen cuoi tinh yeu, truyen cuoi the thao, truyen cuoi gia dinh, truyen cuoi nghe nghiep";
            $headKey .= "truyen cuoi Vova, truyen cuoi con gai, tho ca cuoi, truyen cuoi giao thong";
            $headKey .= "truyen cuoi y hoc, truyen cuoi phap luat";
            $this->view->headKey = $headKey;
            $this->view->headDescription = "Trang truyện cười xem24.com, cập nhật liên tục, truyện cười hay nhất, mới nhất";
            if(isset($params['type'])){
                $type = $params['type'];
            }else{
                $type = 0;
            }	
            if($type!= 0){
                $this->view->type_name = $category_model->getItem($type);
            }
            $this->view->type = $type;
            $list = $story_model->getList($type, 1);
            $this->view->list_story = $list;
            $this->view->page = 2;
        }   
        }catch(Exception $e){
            exit($e->getMessage());
        }
    }
    
    public function loadMorestoryAction(){
        $this->_helper->_layout->disableLayout();
        Zend_Loader::loadClass("StoryModel");
        $story_model = new StoryModel();
        $page = $this->_arrParam['page'];
        $type = $this->_arrParam['type'];
        $list = $story_model->getList($type, $page);
        if(count($list)){
            $this->view->list_story = $list;
            $this->view->type = $type;
        }else{
            exit();
        }
    }
    
    public function boxVideoAction()
    {
	    //seo
		 $this->view->headTitle("100 Ca khúc nhạc vàng, trữ tình hay nhất mọi thời đại");
         $this->view->headKey = "nhac vang hay,thuy nga, nhac hai ngoai";
         $this->view->headDescription = "Album tuyển chọn 100 bài hat hay nhat chơi list ngẫu nhiên, giúp bạn có phút giây nghe nhạc thoải mái chi co tai xem24.com";
        
        //Tin tuc chi tiet
        $AdsModel = new AdvertiseModel();
        $this->view->ads_top = $AdsModel->getListAdsByPos('home','top');
        $this->view->ads_right = $AdsModel->getListAdsByPos('home','right');
        $this->view->ads_bottom = $AdsModel->getListAdsByPos('home','bottom');
        $channel=$this->_request->getParam('channel');
		if($channel==""){$channel="3|1";}
        $ModelF = new FilmInfoModel();
        $list_box = $ModelF->getListBox($channel);
        $str_list = "";
        $str_des = "";
		
		
        foreach($list_box as $item){
		
            if($str_list == ""){
                $str_list = $item['id_eps'];
                $str_des = $item['des_eps'];
            }  
            else{
                $str_list = $str_list.",".$item['id_eps'];
                $str_des = $str_des."#|#".$item['des_eps'];
            } 
			
        }
   
        $arr_id = explode(',',$str_list);
        $arr_title = explode('#|#',$str_des);
        
        $arr_rand = array_rand($arr_id,100);
        $arr_id_rand = "";
        $arr_title_rand = "";
        foreach($arr_rand as $r){
            if($arr_id_rand == ""){
                $arr_id_rand = $arr_id[$r];
                $arr_title_rand = $arr_title[$r];
            }else{
                $arr_id_rand = $arr_id_rand.",".$arr_id[$r];
                $arr_title_rand = $arr_title_rand."#|#".$arr_title[$r];
            }    
        }
        
        //$arr_id_rand = "'p3SG0xEQHD8',".$arr_id_rand;
        $this->view->ids = $arr_id_rand;
        $this->view->titles = $arr_title_rand;
		
    }
    public function guideAction(){
        $this->view->headTitle("Hướng dẫn");
        
        Zend_Loader::loadClass('GuideModel');
        $GModel = new GuideModel();
        $this->view->text = $GModel->fetchRow("id = '1'");
    }
   
    public function contactAction(){
        $this->view->headTitle("Liên hệ");
        
        Zend_Loader::loadClass('GuideModel');
        $GModel = new GuideModel();
        $this->view->text = $GModel->fetchRow("id = '2'");
    }
    
    public function policyAction(){
        $this->view->headTitle("Bảo mật và điều khoản");
        
        Zend_Loader::loadClass('GuideModel');
        $GModel = new GuideModel();
        $this->view->text = $GModel->fetchRow("id = '3'");
    }
	
	 public function appAction()
    {   $this->_helper->_layout->disableLayout();
        $AdsModel = new AdvertiseModel();
        $FilmInfoModel = new FilmInfoModel();
        if(isset($this->_arrParam['cate']) && !isset($this->_arrParam['type'])){
             //TRANG The loai
            $this->view->ads_top = $AdsModel->getListAdsByPos('category1','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('category1','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('category1','bottom');
    
            $cate = $this->_arrParam['cate'];
            $listFilm = $FilmInfoModel->getListFilmByCate_m($cate); 
            $this->view->listFilm = $listFilm;
            
            $meta_title = $listFilm[0]['name'];
            $this->view->headTitle($meta_title."| Xem24.com");
            $this->view->headKey = $meta_title ;
            
            $ParentTypeModel = new ParentTypeModel();
            $description = $ParentTypeModel->getTypeById($cate);
            $description = $description[0]['description'];
        }
        else if(isset($this->_arrParam['cate']) && isset($this->_arrParam['type'])){
            
             //TRANG The loai
            $this->view->ads_top = $AdsModel->getListAdsByPos('category2','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('category2','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('category2','bottom');
            //
            $cate = $this->_arrParam['cate'];
            $type = $this->_arrParam['type'];
            $cates = $FilmInfoModel->getListFilmByCate_m($cate);
            $j = 0;
            foreach($cates as $item){
                $types = explode('|',$item['type']);
                for($i = 1; $i<count($types);$i++){
                    if($types[$i] == $type){
                        $listFilm[] = $cates[$j];
                    }
                }
                $j++;  
            }
            $name_type = explode('|',$cates[0]['name_types']);
            for($j = 0 ; $j < count($name_type); $j++)
            {
                $name_type[$j] = explode('-',$name_type[$j]);
                if($name_type[$j][0] == $type){
                    $meta_title = $name_type[$j][1];
                }
                
            }
            //$meta_title = $name_type['name'];
            $this->view->headTitle($meta_title." | Xem24.com");
			$this->view->headKey = $meta_title ;
            $this->view->label_top = $meta_title;
           //$this->view->headDescription =$film[0]['description'];
           
            $adapter = new Zend_Paginator_Adapter_Array($listFilm);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(21);       
            $paginator->setPageRange(3);
            $currentPage = $this->_request->getParam('page',1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->paginator=$paginator;
        }else
        if(isset($this->_arrParam['id'])){
            
             //TRANG Chi tieets
            $this->view->ads_top = $AdsModel->getListAdsByPos('detail','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('detail','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('detail','bottom');
            //
            
            $id = $this->_arrParam['id'];
            
            $film = $FilmInfoModel->getFilmById($this->_arrParam['id']);
            // meta cho trang chi tiet
            $meta_title = $film[0]['title_vi'];
            $this->view->headTitle($meta_title." | Xem24.com ");
            $this->view->headKey = $meta_title ;
            $this->view->headDescription =$film[0]['description'];
            
            
            $type = $film[0]['type'];
            $type = explode('|',$type,2);
            $type = intval($type[0]);
            
             $this->view->film = $film;
             $hits = $FilmInfoModel->getHitsById($id);
             $hit = $hits[0]['hits'];
             $FilmInfoModel->updateHitsById($hit+1,$id);
             
             //xuat top xem nhieu
             $topVideo = $FilmInfoModel->getListTop($type);
             $this->view->topvideo = $topVideo;
             
             //xuat video liên quan
             $relatedVideo = $FilmInfoModel->getListRelated($type, $id);
             $this->view->relatedvideo = $relatedVideo;
             
        }else{
            //TRANG CHU
            Zend_Loader::loadClass('TopWeekModel');
            $FilmInfoModel = new FilmInfoModel();
            $TopWeekModel =  new TopWeekModel();
             
            $date_default = '2013-1-28';
            $date_default = strtotime($date_default);
            $Date = new Zend_Date();
            $date_now = $Date->get('yyyy-MM-dd');
            $date_now =  strtotime($date_now);
    
            $date_diff = $date_now - $date_default;
            $day_diff = $date_diff / 86400;
            $week_number = ($day_diff - $day_diff%7)/7;
             
            $topVideo = $TopWeekModel->getListTopAll_m($week_number);
            $this->view->topvideo = $topVideo;
            
            $nominationVideo = $FilmInfoModel->getListNomination_m();
            $this->view->nominationvideo = $nominationVideo;    
            
            $newVideo = $FilmInfoModel->getListNew_m();
            $this->view->newvideo = $newVideo;
            
            /*
            $this->view->ads_top = $AdsModel->getListAdsByPos('home','top');
            $this->view->ads_right = $AdsModel->getListAdsByPos('home','right');
            $this->view->ads_bottom = $AdsModel->getListAdsByPos('home','bottom');
            //
            $typeModel = new ParentTypeModel();
            $types = $typeModel->getListType();
            $this->view->types = $types;
            for($i = 0; $i<count($types); $i++){
                $id = (int)$types[$i]['id'];
                $listNew[] = $FilmInfoModel->getListNew($id);
            }
            $this->view->listNew = $listNew;
            */
        }
    }
    
    public function newAction(){
        
            Zend_Loader::loadClass('FilmInfoModel');
            $FilmInfoModel = new FilmInfoModel(); 
             $channel=$this->_request->getParam('channel');
            //$newVideo = $FilmInfoModel->getListNew_app();
			if(!$channel){
			 $channel="3";// mac dinh la nhac vang
			 }
            if($channel){
			$newVideo = $FilmInfoModel->getListNew_channel($channel, 1);
			}
			$this->view->channel=$channel;
            $this->view->videos = $newVideo;
            $this->view->page = 1;
    }
    
    public function loadMorenewAction(){
        $this->_helper->_layout->disableLayout();
        Zend_Loader::loadClass('FilmInfoModel');
        $FilmInfoModel = new FilmInfoModel(); 
        $page = $this->_arrParam['page'];
        $channel = $this->_arrParam['channel'];
        $newVideo = $FilmInfoModel->getListNew_channel($channel, $page);
        if(count($newVideo)){
            $this->view->videos = $newVideo;
            $this->view->channel=$channel;
        }else{
            exit();
        }
    }
    
	public function topAction()
	{
			Zend_Loader::loadClass('TopWeekModel');
	        $TopWeekModel =  new TopWeekModel();
             
            $date_default = '2013-1-28';
            $date_default = strtotime($date_default);
            $Date = new Zend_Date();
            $date_now = $Date->get('yyyy-MM-dd');
            $date_now =  strtotime($date_now);
    
            $date_diff = $date_now - $date_default;
            $day_diff = $date_diff / 86400;
            $week_number = ($day_diff - $day_diff%7)/7;
          
			 $channel=$this->_request->getParam('channel');
			 if(!$channel){
			 $channel="3";
			 }
			//channel kenh cho app
            if($channel){
            $topVideo = $TopWeekModel->getListTopAll_app_channel($week_number,$channel,1);
			//$nominationVideo = $FilmInfoModel->getListNomination_channel($channel);
			//$newVideo = $FilmInfoModel->getListNew_channel($channel);
			}
            $this->view->week_number = $week_number;
            $this->view->videos = $topVideo;
            $this->view->page = 1;
            $this->view->channel = $channel;
		
    }
    
     public function loadMoretopAction(){
        $this->_helper->_layout->disableLayout();
        Zend_Loader::loadClass('TopWeekModel');
        $TopWeekModel =  new TopWeekModel();
        $page = $this->_arrParam['page'];
        $week_number = $this->_arrParam['week_number'];
        $channel = $this->_arrParam['channel'];
        $topVideo = $TopWeekModel->getListTopAll_app_channel($week_number,$channel,$page);
        if(count($topVideo)){
            $this->view->videos = $topVideo;
        }else{
            exit();
        }
    }
    
	//bat tat quang cao 
	
	 
    public function activeqcAction(){
	     $content =  "<div id='sunnet_widget_44' style='display: none;'></div>";
         $content .= "<script type='text/javascript'>var is_load_sunnet_lib = is_load_sunnet_lib || 1;if(is_load_sunnet_lib == 1)";
         $content .= "{is_load_sunnet_lib = 2;if(typeof(jQuery)=='undefined') {document.write(unescape('%3Cscript src=\'http://amobi.vn/js/default/jquery-1.7.2.min.js\' type=\'text/javascript\'%3E%3C/script%3E'));}document.write(unescape('%3Cscript src=\'http://amobi.vn/js/default/sunnet.js\' type=\'text/javascript\'%3E%3C/script%3E'));}</script>";
         $content .= "<script type='text/javascript' src='http://amobi.vn/default/index/widget?widget_id=44'></script>";
        
	 
		 $content3 = '<center><a href="http://i.qplay.vn/168-0-0-0--1/ung-dung/Nhac-Vang-HD.html"> <img src="/images/sys/icon_app.jpg"  height="50"/> </a></center> ';
         $content0=0;
		 $content1=1;
		 $this->_helper->layout()->disableLayout(); 
         $this->_helper->viewRenderer->setNoRender(true);
	       //echo "xem24.com";
	    echo  $content3;
		//1 la cho quang cao chay cong ty 
		//0 la khoong cho chay
		// khac 0 , 1 la quang cao mac dinh 
    }
   
 public function activeqc2Action(){
         		
		$content =  " <div id='seo_widget_33' style='display: none;'></div>";
		$content .= " <script type='text/javascript'>var is_load_seo_lib = is_load_seo_lib || 1;if(is_load_seo_lib == 1) {is_load_seo_lib = 2;if(typeof(jQuery)=='undefined') {document.write(unescape('%3Cscript src='http://linkseo.info/js/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E'));}document.write(unescape('%3Cscript src='http://linkseo.info/js/widget.js' type='text/javascript'%3E%3C/script%3E'));}</script>";
		$content .= "<script type='text/javascript' src='http://linkseo.info/index/widget?id=33'></script>";
		//echo $content;
			
	     $qc3 = '<a href="http://qplay.vn"> <img src="http://www.cdc.gov/actagainstaids/images/reasons_banner_320x50.jpg"></img></a> ';
         $qc0=0;
		 $qc1=1;
		
		 $this->_helper->layout()->disableLayout(); 
         $this->_helper->viewRenderer->setNoRender(true);
	
	     echo   $qc0;
		//1 la cho quang cao chay cong ty 
		//0 la khoong cho chay
		// khac 0 , 1 la quang cao mac dinh 
    }
   
   public function activeqc3Action(){
	
	 
		 $content3 = '<a href="http://qplay.vn"> <img src="http://www.cdc.gov/actagainstaids/images/reasons_banner_320x50.jpg"></img></a> ';
         $content0=0;
		 $content1=1;
		 $this->_helper->layout()->disableLayout(); 
         $this->_helper->viewRenderer->setNoRender(true);
	
	    echo  $content0=0;
		//1 la cho quang cao chay cong ty 
		//0 la khoong cho chay
		// khac 0 , 1 la quang cao mac dinh 
    }
   
   
 
}

